<?php
/**
 * [WeEngine System] Copyright (c) 2014 WE7.CC
 * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
 */
ini_set('display_errors', '1');
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);

ob_start();
define('IA_ROOT', str_replace("\\",'/', dirname(__FILE__)));

//setcookie('action', 'license');

$action = !empty($_COOKIE['action']) ? $_COOKIE['action'] : 'license';
$ispost = strtolower($_SERVER['REQUEST_METHOD']) == 'post';

if( file_exists(IA_ROOT . '/appct/Common/Conf/install.lock') && $action!='finish' ) {
	header('location: ./index.php');
	exit;
}
header('content-type: text/html; charset=utf-8');

if($action == 'license') {
	if($ispost) {
		setcookie('action', 'env');
		header('location: ?refresh');
		exit;
	}
	tpl_install_license();
}

if($action == 'env') {
	if($ispost) {
		setcookie('action', $_POST['do'] == 'continue' ? 'db' : 'license');
		header('location: ?refresh');
		exit;
	}
	$ret = array();
	$ret['server']['os']['value'] = php_uname();
	if(PHP_SHLIB_SUFFIX == 'dll') {
		$ret['server']['os']['remark'] = '建议使用 Linux 系统以提升程序性能';
		$ret['server']['os']['class'] = 'warning';
	}
	$ret['server']['sapi']['value'] = $_SERVER['SERVER_SOFTWARE'];
	if(PHP_SAPI == 'isapi') {
		$ret['server']['sapi']['remark'] = '建议使用 Apache 或 Nginx 以提升程序性能';
		$ret['server']['sapi']['class'] = 'warning';
	}
	$ret['server']['php']['value'] = PHP_VERSION;
	$ret['server']['dir']['value'] = IA_ROOT;
	if(function_exists('disk_free_space')) {
		$ret['server']['disk']['value'] = floor(disk_free_space(IA_ROOT) / (1024*1024)).'M';
	} else {
		$ret['server']['disk']['value'] = 'unknow';
	}
	$ret['server']['upload']['value'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknow';

	$ret['php']['version']['value'] = PHP_VERSION;
	$ret['php']['version']['class'] = 'success';
	if(version_compare(PHP_VERSION, '5.5.0') == -1) {
		$ret['php']['version']['class'] = 'danger';
		$ret['php']['version']['failed'] = true;
		$ret['php']['version']['remark'] = 'PHP版本必须为 5.5.0 以上. <a href="#">详情</a>';
	}

	$ret['php']['pdo']['ok'] = extension_loaded('pdo') && extension_loaded('pdo_mysql');
	if($ret['php']['pdo']['ok']) {
		$ret['php']['pdo']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['php']['pdo']['class'] = 'success';
	} else {
		$ret['php']['pdo']['failed'] = true;
		$ret['php']['pdo']['value'] = '<span class="glyphicon glyphicon-remove text-warning"></span>';
		$ret['php']['pdo']['class'] = 'warning';
		$ret['php']['pdo']['remark'] = '您的PHP环境不支持PDO, 请开启此扩展. <a target="_blank" href="#">详情</a>';
	}

	$ret['php']['fopen']['ok'] = @ini_get('allow_url_fopen') && function_exists('fsockopen');
	if($ret['php']['fopen']['ok']) {
		$ret['php']['fopen']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
	} else {
		$ret['php']['fopen']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
	}

	$ret['php']['curl']['ok'] = extension_loaded('curl') && function_exists('curl_init');
	if($ret['php']['curl']['ok']) {
		$ret['php']['curl']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['php']['curl']['class'] = 'success';
	} else {
		$ret['php']['curl']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
		$ret['php']['curl']['class'] = 'danger';
		$ret['php']['curl']['remark'] = '您的PHP环境不支持cURL, 也不支持 allow_url_fopen, 系统无法正常运行. <a target="_blank" href="#">详情</a>';
		$ret['php']['curl']['failed'] = true;
	}

	$ret['php']['ssl']['ok'] = extension_loaded('openssl');
	if($ret['php']['ssl']['ok']) {
		$ret['php']['ssl']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['php']['ssl']['class'] = 'success';
	} else {
		$ret['php']['ssl']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
		$ret['php']['ssl']['class'] = 'danger';
		$ret['php']['ssl']['failed'] = true;
		$ret['php']['ssl']['remark'] = '没有启用OpenSSL, 将无法访问公众平台的接口, 系统无法正常运行. <a target="_blank" href="#">详情</a>';
	}

	$ret['php']['gd']['ok'] = extension_loaded('gd');
	if($ret['php']['gd']['ok']) {
		$ret['php']['gd']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['php']['gd']['class'] = 'success';
	} else {
		$ret['php']['gd']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
		$ret['php']['gd']['class'] = 'danger';
		$ret['php']['gd']['failed'] = true;
		$ret['php']['gd']['remark'] = '没有启用GD, 将无法正常上传和压缩图片, 系统无法正常运行. <a target="_blank" href="#">详情</a>';
	}

	$ret['php']['dom']['ok'] = class_exists('DOMDocument');
	if($ret['php']['dom']['ok']) {
		$ret['php']['dom']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['php']['dom']['class'] = 'success';
	} else {
		$ret['php']['dom']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
		$ret['php']['dom']['class'] = 'danger';
		$ret['php']['dom']['failed'] = true;
		$ret['php']['dom']['remark'] = '没有启用DOMDocument, 将无法正常安装使用模块, 系统无法正常运行. <a target="_blank" href="#">详情</a>';
	}

	$ret['php']['session']['ok'] = ini_get('session.auto_start');
	if($ret['php']['session']['ok'] == 0 || strtolower($ret['php']['session']['ok']) == 'off') {
		$ret['php']['session']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['php']['session']['class'] = 'success';
	} else {
		$ret['php']['session']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
		$ret['php']['session']['class'] = 'danger';
		$ret['php']['session']['failed'] = true;
		$ret['php']['session']['remark'] = '系统session.auto_start开启, 将无法正常注册会员, 系统无法正常运行. <a target="_blank" href="http://bbs.we7.cc/forum.php?mod=redirect&goto=findpost&ptid=3564&pid=58111">详情</a>';
	}

	$ret['php']['asp_tags']['ok'] = ini_get('asp_tags');
	if(empty($ret['php']['asp_tags']['ok']) || strtolower($ret['php']['asp_tags']['ok']) == 'off') {
		$ret['php']['asp_tags']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['php']['asp_tags']['class'] = 'success';
	} else {
		$ret['php']['asp_tags']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
		$ret['php']['asp_tags']['class'] = 'danger';
		$ret['php']['asp_tags']['failed'] = true;
		$ret['php']['asp_tags']['remark'] = '请禁用可以使用ASP 风格的标志，配置php.ini中asp_tags = Off';
	}

	$ret['write']['data']['ok'] = local_writeable(IA_ROOT . '/appct/Common/Conf');
	if($ret['write']['data']['ok']) {
		$ret['write']['data']['value'] = '<span class="glyphicon glyphicon-ok text-success"></span>';
		$ret['write']['data']['class'] = 'success';
	} else {
		$ret['write']['data']['value'] = '<span class="glyphicon glyphicon-remove text-danger"></span>';
		$ret['write']['data']['class'] = 'danger';
		$ret['write']['data']['failed'] = true;
		$ret['write']['data']['remark'] = 'Conf目录无法写入, 将无法写入配置文件, 系统无法正常安装.';
	}

	$ret['continue'] = true;
	foreach($ret['php'] as $opt) {
		if($opt['failed']) {
			$ret['continue'] = false;
			break;
		}
	}
	if($ret['write']['failed']) {
		$ret['continue'] = false;
	}
	tpl_install_env($ret);
}

if($action == 'db') {
	if($ispost) {
		if($_POST['do'] != 'continue') {
			setcookie('action', 'env');
			header('location: ?refresh');
			exit();
		}
		$family = $_POST['family'] == 'x' ? 'x' : 'v';
		$db = $_POST['db'];
		$user = $_POST['user'];
		try {
			$pieces = explode(':', $db['server']);
			$db['server'] = $pieces[0];
			$db['port'] = !empty($pieces[1]) ? $pieces[1] : '3306';
			$link = new PDO("mysql:host={$db['server']};port={$db['port']}", $db['username'], $db['password']); 
			$link->exec("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary");
			$link->exec("SET sql_mode=''");
			if ($link->errorCode() != '00000') {
				$errorInfo = $link->errorInfo();
				$error = $errorInfo[2];
			} else {
				$statement = $link->query("SHOW DATABASES LIKE '{$db['name']}';");
				$fetch = $statement->fetch();
				if (empty($fetch)){
					if (substr($link->getAttribute(PDO::ATTR_SERVER_VERSION), 0, 3) > '4.1') {
						$link->query("CREATE DATABASE IF NOT EXISTS `{$db['name']}` DEFAULT CHARACTER SET utf8");
					} else {
						$link->query("CREATE DATABASE IF NOT EXISTS `{$db['name']}`");
					}
				}
				$statement = $link->query("SHOW DATABASES LIKE '{$db['name']}';");
				$fetch = $statement->fetch();
				if (empty($fetch)) {
					$error .= "数据库不存在且创建数据库失败. <br />";
				}
				if ($link->errorCode() != '00000') {
					$errorInfo = $link->errorInfo();
					$error .= $errorInfo[2];
				}
			}
		} catch (PDOException $e) {
			$error = $e->getMessage();
			if (strpos($error, 'Access denied for user') !== false) {
				$error = '您的数据库访问用户名或是密码错误. <br />';
			} else {
				$error = iconv('gbk', 'utf8', $error);
			}
		}
		
		/*if(empty($error)) {
			$link->exec("USE {$db['name']}");
			$statement = $link->query("SHOW TABLES LIKE '{$db['prefix']}%';");
			if ($statement->fetch()) {
				$error = '您的数据库不为空，请重新建立数据库或是清空该数据库或更改表前缀！';
			}
		}*/
		
		if(empty($error)) {
			$setfile = IA_ROOT.'/appct/Common/Conf/config.php'; 
			if( !file_exists($setfile) ){
				$myfile = fopen($setfile, "w") or die("Unable to open file!");
				$txt = "<?php  \nreturn array(\n";
				$txt.="   'DB_TYPE'=>'mysql', \n";
				$txt.="   'DB_HOST'=>'".$db['server']."', \n";
				$txt.="   'DB_NAME'=>'".$db['name']."', \n";
				$txt.="   'DB_USER'=>'".$db['username']."', \n";
				$txt.="   'DB_PWD'=>'".$db['password']."', \n";
				$txt.="   'DB_PORT'=>'".$db['port']."', \n";
				$txt.="   'DB_PREFIX'=>'".$db['prefix']."', \n";
				$txt.="   'SHOW_ERROR_MSG'=>true \n";
				$txt.=");\n?>";
				fwrite($myfile, $txt);
				fclose($myfile);
				touch(IA_ROOT . '/appct/Common/Conf/install.lock');
			}
			require IA_ROOT . '/appct/Common/Conf/db.php';
			setcookie('action', 'finish');
			header('location: ?refresh');
			exit();
		}
	}
	tpl_install_db($error);
}

if($action == 'finish') {
	setcookie('action', '', -10);
	$dbfile = IA_ROOT . '/appct/Common/Conf/db.php';
	@unlink($dbfile);
	$sxkj_offline = IA_ROOT . '/sxkj_offline.zip';
	@unlink($sxkj_offline);
	tpl_install_finish();
}

function local_writeable($dir) {
	$writeable = 0;
	if(!is_dir($dir)) {
		@mkdir($dir, 0777);
	}
	if(is_dir($dir)) {
		if($fp = fopen("$dir/test.txt", 'w')) {
			fclose($fp);
			unlink("$dir/test.txt");
			$writeable = 1;
		} else {
			$writeable = 0;
		}
	}
	return $writeable;
}

function tpl_frame() {
	$tpl = <<<EOF
		<!DOCTYPE html>
			<html lang="zh">
			<head>
			<meta charset="UTF-8">
			<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
			<meta name="viewport" content="width=device-width, initial-scale=1.0">
			<title></title>
			<link rel="stylesheet" href="./Public/lib/bootstrap/css/bootstrap.css">
			<link rel="stylesheet" href="./Public/css/install.css?12">
			<script src="./Public/js/jquery.min.js"></script>
			<script src="./Public/lib/bootstrap/js/bootstrap.min.js"></script>	
			</head>
			<body>
			<div class="jq22-container">
				<header class="jq22-header">
					<h1 style="position:relative;display:inline-block;padding-left:120px;">随心科技联通CPS安装流程</h1>
					<a href="http://www.sxsxjzw.com/"><div class="nav_a">进入随心科技官网 ></div></a>
				</header>	
EOF;
	echo trim($tpl);
}

function tpl_install_license() {
	tpl_frame();
	echo <<<EOF
	<div class="tabs">
	  <input type="radio" id="tab1" name="tab-control" checked>
	  <input type="radio" id="tab2" name="tab-control">
	  <input type="radio" id="tab3" name="tab-control">  
	  <input type="radio" id="tab4" name="tab-control">
	  <ul>
		<li>
			<label><span>①安装许可&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>②环境监测&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>③参数配置&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>④成功&nbsp;&nbsp;</span></label>
		</li>
	  </ul>
	  <div class="slider"><div class="indicator"></div></div>
	  <div class="content">
			<section>
				<div class="add_d1">版权所有 (c)2018，随心科技团队保留所有权利。
				感谢您选择随心科技 - 联通手机卡在线分销系统（以下简称基于 PHP + MySQL的技术开发，本系统用户进行手机卡在线申请分销返佣功能。 
				为了使你正确并合法的使用本软件，请你在使用前务必阅读清楚下面的协议条款：

				一、本授权协议适用且仅适用于随心科技系统(话费cps. 以下简称随心科技)任何版本，随心科技官方对本授权协议的最终解释权。

				二、协议许可的权利

				本系统仅允许搭建和使用，不允许商业二开和运营，本系统已获得软著，任何商业二开必须获得我司授权，授权免费，否则视为盗版，我司保留追究权力。
				
				三、协议规定的约束和限制

				未经官方许可，不得对本软件或与之关联的商业授权进行出租、出售、抵押或发放子许可证。
				未经官方许可，禁止在随心科技的整体或任何部分基础上以发展任何派生版本、修改版本或第三方版本用于重新分发。
				如果您未能遵守本协议的条款，您的授权将被终止，所被许可的权利将被收回，并承担相应法律责任。
				四、有限担保和免责声明

				本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的。
				用户出于自愿而使用本软件，您必须了解使用本软件的风险，在尚未购买产品技术服务之前，我们不承诺对免费用户提供任何形式的技术支持、使用担保，也不承担任何因使用本软件而产生问题的相关责任。
				电子文本形式的授权协议如同双方书面签署的协议一样，具有完全的和等同的法律效力。您一旦开始确认本协议并安装 ，即被视为完全理解并接受本协议的各项条款，在享有上述条款授予的权力的同时，受到相关的约束和限制。协议许可范围以外的行为，将直接违反本授权协议并构成侵权，我们有权随时终止授权，责令停止损害，并保留追究相关责任的权力。
				如果本软件带有其它软件的整合API示范例子包，这些文件版权不属于本软件官方，并且这些文件是没经过授权发布的，请参考相关软件的使用许可合法的使用。</div>
				<form class="form-inline" role="form" method="post">	
					<div class="add_d2">
						<label class="ipt1">
							<input type="checkbox">我已经阅读并同意此协议
						</label>
						<div class="btn1" onclick="if(jQuery(':checkbox:checked').length == 1){jQuery('form')[0].submit();}else{alert('您必须同意软件许可协议才能安装！')};"> 继续 > </div>
					</div>
				</form>	
			</section>
	  </div>
	</div>
</div>
</body>
</html>		
EOF;
}

function tpl_install_env($ret = array()) {	
	tpl_frame();
	if(empty($ret['continue'])) {
		$continue = '<div class="btn2">请先解决环境问题后继续</div>';
	} else {
		$continue = '<div class="btn1" onclick="$(\'#do\').val(\'continue\');$(\'form\')[0].submit();"> 继续 ></div>';
	}				
	echo <<<EOF
		<div class="tabs">
	  <input type="radio" id="tab1" name="tab-control">
	  <input type="radio" id="tab2" name="tab-control" checked>
	  <input type="radio" id="tab3" name="tab-control">  
	  <input type="radio" id="tab4" name="tab-control">
	  <ul>
		<li>
			<label><span>①安装许可&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>②环境监测&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>③参数配置&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>④成功&nbsp;&nbsp;</span></label>
		</li>
	  </ul>
	  <div class="slider"><div class="indicator"></div></div>
	  <div class="content">
	  		<section></section>	  			
			<section>
				<div class="add_d3">
					<div class="panel panel-default">
						<div class="panel-heading">服务器信息</div>
						<table class="table table-striped">
							<tr>
								<th style="width:150px;">参数</th>
								<th>值</th>
								<th></th>
							</tr>
							<tr class="{$ret['server']['os']['class']}">
								<td>服务器操作系统</td>
								<td>{$ret['server']['os']['value']}</td>
								<td>{$ret['server']['os']['remark']}</td>
							</tr>
							<tr class="{$ret['server']['sapi']['class']}">
								<td>Web服务器环境</td>
								<td>{$ret['server']['sapi']['value']}</td>
								<td>{$ret['server']['sapi']['remark']}</td>
							</tr>
							<tr class="{$ret['server']['php']['class']}">
								<td>PHP版本</td>
								<td>{$ret['server']['php']['value']}</td>
								<td>{$ret['server']['php']['remark']}</td>
							</tr>
							<tr class="{$ret['server']['dir']['class']}">
								<td>程序安装目录</td>
								<td>{$ret['server']['dir']['value']}</td>
								<td>{$ret['server']['dir']['remark']}</td>
							</tr>
							<tr class="{$ret['server']['disk']['class']}">
								<td>磁盘空间</td>
								<td>{$ret['server']['disk']['value']}</td>
								<td>{$ret['server']['disk']['remark']}</td>
							</tr>
							<tr class="{$ret['server']['upload']['class']}">
								<td>上传限制</td>
								<td>{$ret['server']['upload']['value']}</td>
								<td>{$ret['server']['upload']['remark']}</td>
							</tr>
						</tbody></table>
					</div>
					<div class="alert alert-info">PHP环境要求必须满足下列所有条件，否则系统或系统部份功能将无法使用。</div>
					<div class="panel panel-default">
						<div class="panel-heading">PHP环境要求</div>
						<table class="table table-striped"><tbody>
							<tr>
								<th style="width:150px;">选项</th>
								<th style="width:180px;">要求</th>
								<th style="width:50px;">状态</th>
								<th>说明及帮助</th>
							</tr>
							<tr class="{$ret['php']['version']['class']}">
								<td>PHP版本</td>
								<td>5.3或者5.3以上</td>
								<td>{$ret['php']['version']['value']}</td>
								<td>{$ret['php']['version']['remark']}</td>
							</tr>
							<tr class="{$ret['php']['curl']['class']}">
								<td>cURL</td>
								<td>支持</td>
								<td>{$ret['php']['curl']['value']}</td>
								<td>{$ret['php']['curl']['remark']}</td>
							</tr>
							<tr class="{$ret['php']['pdo']['class']}">
								<td>PDO</td>
								<td>支持</td>
								<td>{$ret['php']['pdo']['value']}</td>
								<td>{$ret['php']['pdo']['remark']}</td>
							</tr>
							<tr class="{$ret['php']['ssl']['class']}">
								<td>openSSL</td>
								<td>支持</td>
								<td>{$ret['php']['ssl']['value']}</td>
								<td>{$ret['php']['ssl']['remark']}</td>
							</tr>
							<tr class="{$ret['php']['gd']['class']}">
								<td>GD2</td>
								<td>支持</td>
								<td>{$ret['php']['gd']['value']}</td>
								<td>{$ret['php']['gd']['remark']}</td>
							</tr>
							<tr class="{$ret['php']['dom']['class']}">
								<td>DOM</td>
								<td>支持</td>
								<td>{$ret['php']['dom']['value']}</td>
								<td>{$ret['php']['dom']['remark']}</td>
							</tr>
							<tr class="{$ret['php']['session']['class']}">
								<td>session.auto_start</td>
								<td>关闭</td>
								<td>{$ret['php']['session']['value']}</td>
								<td>{$ret['php']['session']['remark']}</td>
							</tr>
							<tr class="{$ret['php']['asp_tags']['class']}">
								<td>asp_tags</td>
								<td>关闭</td>
								<td>{$ret['php']['asp_tags']['value']}</td>
								<td>{$ret['php']['asp_tags']['remark']}</td>
							</tr>
						</tbody></table>
					</div>
					<div class="alert alert-info">系统要求整个安装目录必须可写。</div>
					<div class="panel panel-default">
						<div class="panel-heading">目录权限监测</div>
						<table class="table table-striped"><tbody>
							<tr>
								<th style="width:150px;">目录</th>
								<th style="width:180px;">要求</th>
								<th style="width:50px;">状态</th>
								<th>说明及帮助</th>
							</tr>
							<tr class="{$ret['write']['data']['class']}">
								<td>/appct/Common/Conf</td>
								<td>Conf目录可写</td>
								<td>{$ret['write']['data']['value']}</td>
								<td>{$ret['write']['data']['remark']}</td>
							</tr>
						</tbody></table>
					</div>
				</div>
				<form class="form-inline" role="form" method="post">
					<div class="add_d2">
						<input type="hidden" name="do" id="do" />
						<div class="btn1" onclick="$('#do').val('back');$('form')[0].submit();">< 返回 </div>
						{$continue}						
					</div>
				</form>				
			</section>
	  	</div>
	</div>
</div>
</body>
</html>		
EOF;
}

function tpl_install_db($error = '') {
	if(!empty($error)) {
		$message = '<div class="alert alert-danger">发生错误: ' . $error . '</div>';
	}
	$insTypes = array();
	if(file_exists(IA_ROOT . '/index.php') && is_dir(IA_ROOT . '/app') && is_dir(IA_ROOT . '/web')) {
		$insTypes['local'] = ' checked="checked"';
	} else {
		$insTypes['remote'] = ' checked="checked"';
	}
	if (!empty($_POST['type'])) {
		$insTypes = array();
		$insTypes[$_POST['type']] = ' checked="checked"';
	}
	$disabled = empty($insTypes['local']) ? ' disabled="disabled"' : '';
	
	tpl_frame();
	echo <<<EOF
	{$message}
	<div class="tabs">
	  <input type="radio" id="tab1" name="tab-control">
	  <input type="radio" id="tab2" name="tab-control">
	  <input type="radio" id="tab3" name="tab-control" checked>  
	  <input type="radio" id="tab4" name="tab-control">
	  <ul>
		<li>
			<label><span>①安装许可&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>②环境监测&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>③参数配置&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>④成功&nbsp;&nbsp;</span></label>
		</li>
	  </ul>
	  <div class="slider"><div class="indicator"></div></div>
	  <div class="content">
			<section></section>
			<section></section>
			<section>
				<form class="form-horizontal" method="post" role="form">
					<div class="add_d3">
						<div class="panel panel-default">
							<div class="panel-heading">数据库选项</div>
							<div class="add_d4"> </div>
							<div class="add_d4"> </div>
							<div class="add_d4">
								<p>数据库主机</p>
								<input type="text" name="db[server]" value="127.0.0.1" placeholder="请输入数据库主机">
								<div class="clear"></div>
							</div>
							<div class="add_d4">
								<p>数据库名称</p>
								<input type="text" name="db[name]" value="" placeholder="请输入数据库名称">
								<div class="clear"></div>
							</div>	
							<div class="add_d4">
								<p>数据库用户</p>
								<input type="text" name="db[username]" value="root" placeholder="请输入数据库用户">
								<div class="clear"></div>
							</div>
							<div class="add_d4">
								<p>数据库密码</p>
								<input type="text" name="db[password]" placeholder="请输入数据库密码">
								<div class="clear"></div>
							</div>
							<div class="add_d4">
								<p>表前缀</p>
								<input type="text" name="db[prefix]" value="ims_" placeholder="请输入表前缀">
								<div class="clear"></div>
							</div>
							<div class="add_d4"> </div>
							<div class="add_d4"> </div>
						</div>
						<div class="panel panel-default">
							<div class="panel-heading">管理选项</div>
							<div class="add_d4"> </div>
							<div class="add_d4"> </div>
							<div class="add_d4">
								<p>管理员账号</p>
								<input type="text" name="user[username]" placeholder="请输入管理员账号" value="admin" readonly >
								<div class="clear"></div>
							</div>
							<div class="add_d4">
								<p>管理员密码</p>
								<input type="text" name="user[password]" placeholder="请输入管理员密码" value="123456" readonly >
								<div class="clear"></div>
							</div>
							<div class="add_d4"> </div>
							<div class="add_d4"> </div>
						</div>
					</div>
					<input type="hidden" name="do" id="do" />
					<div class="add_d2">
						<div class="btn1" onclick="$('#do').val('back');$('form')[0].submit();">< 返回 </div>
						<div class="btn1" onclick="if(check(this)){jQuery('#do').val('continue');$('form')[0].submit();}"> 继续 ></div>
					</div>
				</form>
			</section>
	  	</div>
	</div>
</div>
<script>
	var lock = false;
	function check(obj) {
		if(lock) {
			return;
		}
		$('.form-control').parent().parent().removeClass('has-error');
		var error = false;
		$('.add_d4 input').each(function(){
			if($(this).val() == '') {
				$(this).parent().parent().addClass('has-error');
				this.focus();
				error = true;
			}
		});
		if(error) {
			alert('请检查未填项');
			return false;
		}
		lock = true;
		$(obj).parent().addClass('disabled');
		$(obj).html('正在执行安装');
		return true;
	}
</script>
</body>
</html>
EOF;
}

function tpl_install_finish() {
	tpl_frame();
	echo <<<EOF
	<<div class="tabs">
	  <input type="radio" id="tab1" name="tab-control">
	  <input type="radio" id="tab2" name="tab-control">
	  <input type="radio" id="tab3" name="tab-control">  
	  <input type="radio" id="tab4" name="tab-control" checked>
	  <ul>
		<li>
			<label><span>①安装许可&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>②环境监测&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>③参数配置&nbsp;&nbsp;</span></label>
		</li>
		<li>
			<label><span>④成功&nbsp;&nbsp;</span></label>
		</li>
	  </ul>
	  <div class="slider"><div class="indicator"></div></div>
	  <div class="content">
	  		<section></section>
			<section></section>
			<section></section>
			<section>
				<div class="apply-finish">
					<div class="apply-finish-header">
						<img src="./Public/images/success1.png">
						<div class="apply-finish-msg">安装成功</div>
					</div>
					<div class="apply-finish-footer">
						<p><a href="./index.php">确定</a></p>
					</div>
				</div>
			</section>
	  	</div>
	</div>
</div>
</body>
</html>
EOF;
	
}

function showerror($errno, $message = '') {
	return array(
		'errno' => $errno,
		'error' => $message,
	);
}

